//
//  PersonViewController.m
//  penzer
//
//  Created by caiyc on 2018/10/2.
//  Copyright © 2018年 caiyc. All rights reserved.
//

#import "PersonViewController.h"
#import "LoginViewController.h"
#import "SaleStaicViewController.h"
#import "Live_HisViewController.h"
#import "SetViewController.h"
#import "MyFenViewController.h"
#import "HostLoginViewController.h"
#import "HostAuthViewController.h"
@interface PersonViewController ()
@property (weak, nonatomic) IBOutlet UIView *user_infoView;
@property (weak, nonatomic) IBOutlet UIView *func_View;
@property (weak, nonatomic) IBOutlet UILabel *perPrice;
@property (weak, nonatomic) IBOutlet UIImageView *sexImg;
@property (weak, nonatomic) IBOutlet UIImageView *icon;
@property (weak, nonatomic) IBOutlet UILabel *age;

@end

@implementation PersonViewController
- (IBAction)exit:(UIButton *)sender {
    //退出登录，清除本地的个人用户信息
    [XTool SaveDefaultInfo:nil Key:HOST_USER];
    [XTool SaveDefaultInfo:@"0" Key:HOST_ONLINE];
    [XTool SaveDefaultInfo:nil Key:Prole];//角色状态清空
    [[NSNotificationCenter defaultCenter]postNotificationName:STOPTIMENOTO object:nil];
   // [XTool SaveDefaultInfo:<#(id)#> Key:<#(NSString *)#>];
    [self.navigationController popViewControllerAnimated:1];
    LoginViewController *vc = [[LoginViewController alloc]init];
    [self pushSecondVC:vc];
}
-(void)viewWillAppear:(BOOL)animated{
    if([XTool GetDefaultInfo:HOST_USER]){
        //登录状态
        NSDictionary *userDic = [XTool GetDefaultInfo:HOST_USER];
        NSString *nickString = userDic[@"nickname"];
        self.nick_name.text = userDic[@"nickname"];
        //avatar
        NSURL *url = [NSURL URLWithString:userDic[@"avatar"]];
        [self.icon sd_setImageWithURL:url];
        CGFloat width = [XTool calculateRowWidth:nickString andHeight:30 andSize:22];
        self.sexImg.frame = CGRectMake(width+self.nick_name.frame.origin.x+10, self.sexImg.frame.origin.y, self.sexImg.frame.size.width, self.sexImg.frame.size.height);
        self.level_img.frame = CGRectMake(self.sexImg.frame.origin.x+self.sexImg.frame.size.width+10, self.level_img.frame.origin.y, self.level_img.frame.size.width, self.level_img.frame.size.height);
        self.auth_Img.frame = CGRectMake(self.level_img.frame.origin.x+self.level_img.frame.size.width+10, self.auth_Img.frame.origin.y, self.auth_Img.frame.size.width, self.auth_Img.frame.size.height);
        self.auth_Btn.frame = CGRectMake(self.level_img.frame.origin.x+self.level_img.frame.size.width+10, self.auth_Btn.frame.origin.y, self.auth_Btn.frame.size.width, self.auth_Btn.frame.size.height);
        NSInteger sex = [userDic[@"sex"]integerValue];
        //is_auth
        NSInteger isauth =  [userDic[@"is_auth"]integerValue];
        if(isauth==0){
            self.auth_Img.image = [UIImage imageNamed:@"weirenzheng"];
        }else{
            self.auth_Btn.userInteractionEnabled = 0;
             self.auth_Img.image = [UIImage imageNamed:@"yirenzheng"];
        }
        if(sex==1){
            self.sexImg.image = [UIImage imageNamed:@"男"];
        }
        self.age.text = [NSString stringWithFormat:@"%@岁",userDic[@"age"]];
        self.perPrice.text = [NSString stringWithFormat:@"¥%@/小时",userDic[@"shenjia"]];
       // self.age.text = userDic[@"age"];
    
    }else{
        //未登录状态
        HostLoginViewController *vc = [[HostLoginViewController alloc]init];
        [self pushSecondVC:vc];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = viewcontrollerColor;
    [self setViews];
    // Do any additional setup after loading the view from its nib.
}
- (IBAction)func_Action:(UIButton *)sender {
    NSInteger indx = sender.tag;
    if(indx==0){
        SaleStaicViewController *vc = [[SaleStaicViewController alloc]init];
        [self pushSecondVC:vc];
    }else if(indx==2){
        Live_HisViewController *vc = [[Live_HisViewController alloc]init];
        [self pushSecondVC:vc];
    }else if (indx==3){
        MyFenViewController *vc = [[MyFenViewController alloc]init];
        [self pushSecondVC:vc];
    }
    else if (indx==4){
        SetViewController *vc = [[SetViewController alloc]init];
        [self pushSecondVC:vc];
    }
}
-(void)setViews{
    self.icon.layer.cornerRadius = 30;
    self.icon.layer.masksToBounds = 1;
    self.botom_ScroView.contentSize = CGSizeMake(screen_width, screen_height*1.2);
    self.botom_ScroView.showsVerticalScrollIndicator = 0;
   self.user_infoView.layer.cornerRadius = 5;
//    self.user_infoView.layer.masksToBounds = 1;
  
    self.func_View.layer.cornerRadius = 5;
  //  self.func_View.layer.masksToBounds = 1;
    
//    self.user_infoView.layer.shadowColor = [UIColor grayColor].CGColor;
//    self.user_infoView.layer.shadowOpacity = 0.8;
//  //  self.user_infoView.layer.shadowOffset = CGSizeMake(5, 5);
//    self.user_infoView.layer.shadowRadius = 5;
//    
//    self.func_View.layer.shadowColor = [UIColor grayColor].CGColor;
//    self.func_View.layer.shadowOpacity = 0.8;
//    //  self.user_infoView.layer.shadowOffset = CGSizeMake(5, 5);
//    self.func_View.layer.shadowRadius = 5;

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)auth_Action:(UIButton *)sender {
    HostAuthViewController *vc = [[HostAuthViewController alloc]init];
    [self pushSecondVC:vc];
}
@end
